<?php
class comment extends serviceAdminBase {
    function __construct() {
        parent::__construct();
        $this->cms->setPageTitle("评价管理");
        $this->cms->setControlFile("service/comment/comment_control.json");
    }

    function indexTask($page=1,$order_id){
        $this->cms->setActionTitle("所有评价");
        $url=WebRouter::init()->getQuestion("page=");
        $page=$page>=1? $page: 1;
        $order_id=isset($order_id)?$order_id:null;
        $countOfPage=20;
        $offset=($page-1)*$countOfPage;
        $user_info=$this->user->getLoginInfo();
        $service=ServiceMode::init();
        $service_id=$service->getServiceId($user_info['id']);
        $comment=CommentModule::init('service_comment','order_id','service_id');
        list($r['comment'],$comment_total)=$comment->getList($order_id,$service_id,$countOfPage,$offset);
        $r['comment']=is_array($r['comment'])?$r['comment']:array();
        $order=OrderMode::init();
        foreach($r['comment'] as &$v){
            $order_info=$order->getDetail($v['order_id']);
            $v['create_time']=$order_info['order']['service_time'];
            $v['service_id']=$order_info['order']['delivery_time'];
        }
        $r['pages']=new Page($page,$comment_total,$countOfPage);
        $r['pages']->setPageCallback(create_function('$page','return "'.$url.'".$page;'));
        $r['score_state']=array('1'=>"1分（这个服务站糟透了）",'2'=>"2分（只能算是勉勉强强）",'3'=>"3分（一般般，没什么出彩的地方）",'4'=>"4分（大体满意）",'5'=>"5分（服务站各方面做的都太棒了）");
        $this->cms->tableScene($r,"service/comment/comment.php");
    }

    function replyTask($id){
        $r['id']=$id;
        $this->cms->formScene($r,"service/comment/reply.php");
    }

    function replySubmitTask($id,$reply){
        $comment=CommentModule::init('service_comment');
        if($comment->addReply($id,$reply)){
            $r['url']=WebRouter::init()->getAction("index");
            $r['message']="回复成功";
        }else{
            $r['message']="回复失败";
        }
        View::displayAsHtml($r,"plugin/state/tips.php");
    }


}